package cameraTool;

import cameraTool.HCNetSDK.NET_DVR_JPEGPARA;

import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.NativeLongByReference;

public class cameraHK {
    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
    static PlayCtrl playControl = PlayCtrl.INSTANCE;

    public static NativeLong g_lVoiceHandle;//全局的语音对讲句柄
        
    HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo;//设备信息
    HCNetSDK.NET_DVR_IPPARACFG_V40  m_strIpparaCfg;//IP参数
    HCNetSDK.NET_DVR_CLIENTINFO m_strClientInfo;//用户参数

    boolean bRealPlay;//是否在预览.
    String m_sDeviceIP;//已登录设备的IP地址

    NativeLong lUserID;//用户句柄
    NativeLong lPreviewHandle;//预览句柄
    NativeLongByReference m_lPort;//回调预览时播放库端口指针
    
    NativeLong lAlarmHandle;//报警布防句柄
    NativeLong lListenHandle;//报警监听句柄
    


    int m_iTreeNodeNum;//通道树节点数目
    
    public cameraHK(){
        lUserID = new NativeLong(-1);
        lPreviewHandle = new NativeLong(-1);
        lAlarmHandle = new NativeLong(-1);
        lListenHandle = new NativeLong(-1);
        g_lVoiceHandle = new NativeLong(-1);
        m_lPort = new NativeLongByReference(new NativeLong(-1));
        m_iTreeNodeNum = 0;
    }
    
    public boolean init()
    {
        boolean initSuc = hCNetSDK.NET_DVR_Init();
        return initSuc;
    }
    
    
    public boolean regist(String ip,int iport,String userName,String password)
    {
        if (lUserID.longValue() > -1)
        {
            //先注销
            hCNetSDK.NET_DVR_Logout_V30(lUserID);
            lUserID = new NativeLong(-1);
            m_iTreeNodeNum = 0;
        }
        //注册
        m_sDeviceIP =ip;//设备ip地址
        m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        int iPort =iport;
        lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP,
                (short) iPort, userName, password, m_strDeviceInfo);

        long userID = lUserID.longValue();
        System.out.println("id:"+userID);
        if (userID == -1)
        {
            m_sDeviceIP = "";//登录未成功,IP置为空
            return false;
        }
        return true;
    }
    
    public boolean takePhoto()
    {
        m_strClientInfo = new HCNetSDK.NET_DVR_CLIENTINFO();
        m_strClientInfo.lChannel = new NativeLong(1);
      //  m_strClientInfo.lLinkMode =new NativeLong(0);
        NET_DVR_JPEGPARA lpJpegPara =new NET_DVR_JPEGPARA();
     //   lpJpegPara.wPicQuality=0;
      //  lpJpegPara.wPicSize=9;
    	System.out.println("a:"+hCNetSDK.NET_DVR_GetLastError());
    //	NET_DVR_SetCapturePictureMode(JPEG_MODE);
    	boolean result =hCNetSDK.NET_DVR_CaptureJPEGPicture(lUserID,new  NativeLong(15),lpJpegPara,"C:/Users/Administrator/Web/CaptureFiles/2018-04-10/test222.jpg");
    	System.out.println("b:"+hCNetSDK.NET_DVR_GetLastError());
    	return result;
    }
    public boolean takePhoto(String Imgpath)
    {
        m_strClientInfo = new HCNetSDK.NET_DVR_CLIENTINFO();
        m_strClientInfo.lChannel = new NativeLong(0);
        NET_DVR_JPEGPARA lpJpegPara =new NET_DVR_JPEGPARA();
    	return hCNetSDK.NET_DVR_CaptureJPEGPicture(lUserID,  m_strClientInfo.lChannel,lpJpegPara,Imgpath);
    }
    public int getErrorCode()
    {
    	return hCNetSDK.NET_DVR_GetLastError();
    }
 
    
    public void getout()
    {
    	hCNetSDK.NET_DVR_Logout(lUserID);   
    	hCNetSDK.NET_DVR_Cleanup(); 
    }
 
}
